部署Apache2.4的Web服务器

您所在的位置:网站首页 破解pdf加密文件 对方会知道吗安全吗苹果 部署Apache2.4的Web服务器

部署Apache2.4的Web服务器

2023-06-05 13:52| 来源: 网络整理| 查看: 265

一、在Vmware 15.5的CentOs 7中安装Web服务器软件包 #验证是否已经安装 rpm -qa|grep httpd #如果没有安装,使用yum命令分别安装: yum -y install httpd yum -y install httpd-tools yum -y install httpd-manual

二、配置DNS服务器 1、修改DNS服务器的主要配置文件 vi /etc/named.conf

options { listen-on port 53 { 192.168.64.63; }; #配置DNS服务器的IP,通过ifconfig获得 listen-on-v6 port 53 { ::1; }; directory "/var/named"; dump-file "/var/named/data/cache_dump.db"; statistics-file "/var/named/data/named_stats.txt"; memstatistics-file "/var/named/data/named_mem_stats.txt"; recursing-file "/var/named/data/named.recursing"; secroots-file "/var/named/data/named.secroots"; allow-query { any; }; #配置允许访问的客户端IP,设置为any允许任何客户端访问 recursion yes; dnssec-enable yes; dnssec-validation yes; /* Path to ISC DLV key */ bindkeys-file "/etc/named.root.key"; managed-keys-directory "/var/named/dynamic"; pid-file "/run/named/named.pid"; session-keyfile "/run/named/session.key"; }; logging { channel default_debug { file "data/named.run"; severity dynamic; }; zone "." IN { type hint; file "named.ca"; }; #配置正向区域,用于正向解析 zone "sh.com" IN { type master; #指定当前配置的是主DNS服务器 file "sh.com.hosts"; #指定正向区域文件名字 }; #配置反向区域,用于反向解析 zone "64.168.192.in-addr.arpa" IN { type master; #指定当前配置的是主DNS服务器 file "192.168.64.rev"; #指定反向区域文件名字 }; include "/etc/named.rfc1912.zones"; include "/etc/named.root.key";

2、编辑正向区域文件 vi /var/named/sh.com.hosts

$ttl 38400 @ IN SOA rhel.sh.com. root.sh.com. ( 1268360234; 10800; 3600; 604800; 38400 ); @ IN NS rhel.sh.com. #指定该区域用于名称解析的服务器 rhel IN A 192.168.64.63 #域名和ip的映射 www IN CNAME rhel.sh.com. #定义域名的别名

3、重新启动DNS服务器 systemctl restart named 或 systemctl start named 三、配置Apache Web服务器 1、编辑Apache Web服务器的主要配置文件: vi /etc/httpd/conf/httpd.conf

ServerRoot "/etc/httpd" #设置服务器的根目录 Listen 80 #设置监听端口 ServerAdmin [email protected] #设置管理员邮箱 ServerName www.sh.com:80 #设置服务器的域名或ip DocumentRoot "/var/www/html" #设置网页内容的根目录 DirectoryIndex index.html index.html #设置起始页文档的名称 AddDefaultCharset UTF-8 #设置默认的编码 User apache #允许访问服务器的用户名 Group apache #允许访问服务器的组名

2、生成网页到指定的目录中 echo This is my first page > /var/www/html/index.html

3、启动web服务 systemctl start httpd.service #后缀.service可以省略

4、设置开机自启web服务 systemctl enable httpd.service 设置完后,可以查询是否设置成功: systemctl is-enabled httpd

注意:此处web服务器的配置是重点,在底行模式下(:wq!)保存配置并启动时,依次遇到的问题及解决方案如下: 1.AH00534: httpd: Configuration error: No MPM loaded. 解决方法: vi /etc/httpd/conf/httpd.conf *在配置文件中添加以下配置,导入指定模块:* LoadModule mpm_prefork_module modules/mod_mpm_prefork.so 2. 错误提示: Invalid command ‘User’ Invalid command 'User', perhaps misspelled or defined by a module not included in the server configuration 解决方法: *加载模块:mod_unixd,在httpd.conf中添加:* LoadModule unixd_module modules/mod_unixd.so 3、错误提示: Invalid command ‘Require’ Invalid command 'Require', perhaps misspelled or defined by a module not included in the server configuration 解决办法:更新配置文件到2.4版本的语法. 包括以下两步: 第一步:加载相应模块,在 httpd.conf 中添加: LoadModule authz_core_module modules/mod_authz_core.so LoadModule authz_host_module modules/mod_authz_host.so 第二步:修改配置文件语法,此处举几个例子: 2.2 版本: Order deny,allow Deny from all 2.4 版本: Require all denied 2.2 版本: Order allow,deny Allow from all 2.4 版本: Require all granted 2.2 版本: Order Deny,AllowDeny from allAllow from example.org 2.4 版本: Require host example.org 4、错误提示:httpd.service stop-sigterm timed out. Killing. 说明:web服务器执行命令systemctl start httpd后,挂机3分钟,启动失败后,使用命令: systemctl status -l httpd查看出错原因,发现上述提示内容。 解决方法: **修改TimeOut超时时间** 编辑apache安装路径/etc/httpd/conf/httpd.conf文件,打开下面一行注释(搜索对应数据(底行模式输入”:/Include conf/“),删除前面的#号) Include conf.modules.d/*.conf **加入httpd-default.conf配置** **修改apache安装路径/etc/httpd/conf.modules.d/httpd-default.conf:** Timeout 15 #(连接超时缺省为300,太大了,缩小会减少同时连接数,即上面占用的实际线程数 KeepAlive On #开启可以提高性能,因为一个页面一般会有多个请求 MaxKeepAliveRequests 50 #这个数目自己根据网页内容调节 KeepAliveTimeout 5 #这个小于Timeout就行 **注意:修改完配置之后,为了使配置生效,启动或重启Apache Web服务器:** systemctl restart httpd.service 或 systemctl start httpd.service

启动成功之后,使用命令systemctl status httpd.service查看Apache web服务器的状态: httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: active (running) since Tue 2023-05-30 10:24:43 CST; 1h 21min ago Docs: man:httpd(8) man:apachectl(8) Main PID: 11622 (httpd) Status: “Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec” CGroup: /system.slice/httpd.service ├─11622 /usr/sbin/httpd -DFOREGROUND ├─11623 /usr/sbin/httpd -DFOREGROUND ├─11624 /usr/sbin/httpd -DFOREGROUND ├─11625 /usr/sbin/httpd -DFOREGROUND ├─11626 /usr/sbin/httpd -DFOREGROUND └─11627 /usr/sbin/httpd -DFOREGROUND

May 30 10:24:42 rhel systemd[1]: Starting The Apache HTTP Server… May 30 10:24:43 rhel httpd[11622]: [Tue May 30 10:24:43.127376 2023] [so:warn] [pid…ing May 30 10:24:43 rhel httpd[11622]: [Tue May 30 10:24:43.141125 2023] [so:warn] [pid…ing May 30 10:24:43 rhel httpd[11622]: [Tue May 30 10:24:43.322021 2023] [so:warn] [pid…ing May 30 10:24:43 rhel httpd[11622]: [Tue May 30 10:24:43.492736 2023] [so:warn] [pid…ing May 30 10:24:43 rhel systemd[1]: Started The Apache HTTP Server. Hint: Some lines were ellipsized, use -l to show in full.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3